export default {
    // 为当前模块开启命名空间
    namespaced: true,
    // 模块的 state 数据
    state: () => ({
        // 上门取件时间
        sellTime: JSON.parse(uni.getStorageSync('sellTime') || '[]'),
        order: JSON.parse(uni.getStorageSync('order') || '[]'),
    }),
    // 模块的 mutations 方法,用来修改state中的数据
    mutations: {
        // 将 sellTime 持久化存储到本地
        saveSellTimeToStorage(state) {
            uni.setStorageSync('sellTime', JSON.stringify(state.sellTime))
        },
        // 将 order 持久化存储到本地
        saveOrderToStorage(state) {
            uni.setStorageSync('order', JSON.stringify(state.order))
        },
        // 向sellTime 添加存储信息
        updataSellTime(state, time) {
            state.sellTime = time
            this.commit('sellOrderStore/saveSellTimeToStorage')
        },
        //添加订单信息
        addorder(state, order) {
            state.order.push(order)
            this.commit('sellOrderStore/saveOrderToStorage')
        },
        //修改订单的地址
        updataAddstr(state, data) {
            const Request = state.order.filter(x => x.order_id === data.id)
            Request.addstr = data.addstr
            // 持久化存储到本地
            this.commit('sellOrderStore/saveOrderToStorage')
        },
        // 删除订单
        deleteOrder(state, id) {
            // 调用数组的 filter 方法进行过滤
            state.order = state.order.filter(x => x.order_id !== id)
            console.log(state.order)
            // 持久化存储到本地
            this.commit('sellOrderStore/saveOrderToStorage')
            uni.showModal({
                title: "提示",
                content: "取消成功",
                confirmText: "确定",
                showCancel: false,
                success: (res2) => {
                    if (res2.confirm) {
                        return;
                    }
                }
            });
        },

    },
    // 模块的 getters 属性，用来对属性进行计算
    getters: {}
}